package com.hna.face.base;

import com.hna.face.model.BfLog;
import com.hna.face.model.BfUser;
import com.hna.face.service.IBfLogService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;


@Controller
public class BaseController {
	private Logger log = LoggerFactory.getLogger(BaseController.class);
	

	@Autowired
	private IBfLogService logService;
	
	/**
	 * 记录操作日志
	 * 
	 * @param request 
	 * @param String description 操作描述
	 * @return 操作结果
	 * @throws
	 */
	public void saveUserlog(HttpServletRequest request,String description){
		try {
			BfUser user = this.getUser(request);
			
			BfLog optlog = new BfLog();
			optlog.setUsername(user.getUsername());
			optlog.setOpttime(new Date());
			optlog.setRemark(description);
			
			logService.insert(optlog);
		} catch(Exception e) {
			log.error("记录操作日志error==="+ e.getMessage(),e);
		}
	}
	
	
	
	public BfUser getUser(HttpServletRequest request){
		BfUser user=(BfUser)request.getSession().getAttribute("userInfo");
		return user;
	}
	
}
